package com.example.wangyongdong.bearsqlitedemo.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by wangyongdong on 2017/4/13.
 */

public class BearSQLiteHelper extends SQLiteOpenHelper{
    private static final String NAME_DB = "oil.db";
    private static final int VERSION = 1;

    public static final String CARS_TBL = "cars_tbl";
    public static final String RECORDS_TBL = "records_tbl";

    //Car的表名
    public static final String _ID = "_id";
    public static final String NAME = "name";
    public static final String SELECTED = "selected";
    public static final String MODEL = "model";
    public static final String UUID = "uuid";

    //Record的表名
    public static final String R_ID = "r_id";
    public static final String DATE = "date";
    public static final String ODOMETER = "odometer";
    public static final String PRICE = "price";
    public static final String YUAN = "yuan";
    public static final String TYPE = "type";
    public static final String GASSUP = "gassup";
    public static final String REMARK = "remark";
    public static final String CARLD = "carld";
    public static final String FORGET = "froget";
    public static final String LIGHTON = "lightOn";
    public static final String STATIONLD = "stationld";

    public BearSQLiteHelper(Context context) {
        super(context, NAME_DB,null,VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //Car建表
        String sqlCar = "create table " + CARS_TBL + " (" + _ID + " integer primary key autoincrement," + NAME + " text not null," + SELECTED + " integer not null," + MODEL + " integer," + UUID + "integer);";
        db.execSQL(sqlCar);
        //Record建表
        String sqlRecord = "create table " + RECORDS_TBL + " (" + R_ID + " integer primary key autoincrement," + DATE + " integer not null," + ODOMETER + " integer not null," + PRICE + " integer not null," + YUAN + " integer not null, " + TYPE + " integer not null, " + GASSUP + " integer not null, " + REMARK + " text not null, " + CARLD + " integer not null, " + FORGET + " integer not null, " + LIGHTON + " integer not null, " + STATIONLD + " integer not null);";
        db.execSQL(sqlRecord);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
